﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>SlideBar - Add/Remove Slides</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../../../css/samples.css" />
    <link rel="stylesheet" href="../../../css/integralui.slidebar.css" />
    <link rel="stylesheet" href="../../../css/themes/theme-flat-blue.css" />
    <script type="text/javascript" src="../../../external/angular.min.js"></script>
    <script type="text/javascript" src="../../../js/angular.integralui.min.js"></script>
    <script type="text/javascript" src="../../../js/angular.integralui.slidebar.min.js"></script>
    <script type="text/javascript">
 		angular
			.module("appModule", ["integralui"])
			.controller("appCtrl", ["$scope", "IntegralUISlideBarService", "$timeout", function($scope, $ctrlService, $timeout){
                $scope.ctrlName = "ctrlSample";
                $scope.insertPos = 0;
                $scope.removePos = 0;
                $scope.disableButtons = false;
                $scope.slides = [
                    { id: 1, name: 'Slide1', text: 'Slide 1' },
                    { id: 2, name: 'Slide2', text: 'Slide 2' },
                    { id: 3, name: 'Slide3', text: 'Slide 3' }
                ];
                
                var slideCount = $scope.slides.length;

                var getCurrentSelection = function(){
                    return $ctrlService.selectedSlide($scope.ctrlName);
                }
                
                var createNewSlide = function(){
                    slideCount++;
                    return { id: slideCount, name: "Slide" + slideCount, text: "Slide " + slideCount };
                }
               
                $scope.add = function(){
                    $ctrlService.addSlide($scope.ctrlName, createNewSlide());
                }
                
                $scope.insertAfter = function(){
                    $ctrlService.insertSlideAfter($scope.ctrlName, createNewSlide(), getCurrentSelection());
                }
                
                $scope.insertAt = function(){
                    $ctrlService.insertSlideAt($scope.ctrlName, createNewSlide(), $scope.insertPos);
                }
                
                $scope.insertBefore = function(){
                    $ctrlService.insertSlideBefore($scope.ctrlName, createNewSlide(), getCurrentSelection());
                }
                
                $scope.remove = function(){
                    $ctrlService.removeSlide($scope.ctrlName, getCurrentSelection());
                }
                
                $scope.removeAt = function(){
                    $ctrlService.removeSlideAt($scope.ctrlName,  $scope.removePos);
                }
                
                $scope.clear = function(){
                    $ctrlService.clearSlides($scope.ctrlName);
                    slideCount = 0;
                }

                $scope.onClear = function(e){
                    updateSlideStripAppearance();
                }

                $scope.onSlideAdded = function(e){
                    updateSlideStripAppearance();

                    $ctrlService.selectedSlide($scope.ctrlName, e.obj);
                }

                $scope.onSlideRemoved = function(e){
                    updateSlideStripAppearance();
                }

                var updateSlideStripAppearance = function(){
                    var updateTimer = $timeout(function(){
                        if ($scope.slides.length == 0){
                            $scope.ctrlBackground = 'white';
                            $scope.ctrlBorder = 'thin solid gray';
                        }
                        else {
                            $scope.ctrlBackground = 'transparent';
                            $scope.ctrlBorder = 'thin solid transparent';
                        }

                        $scope.disableButtons = $scope.slides.length > 0 ? false : true;

                        $timeout.cancel(updateTimer);
                    }, 1);
                }
                
                $scope.ctrlEvents = {
                    clear: function(){
                        return $scope.onClear();
                    },
                    slideAdded: function(e){
                        return $scope.onSlideAdded(e);
                    },
                    slideRemoved: function(e){
                        return $scope.onSlideRemoved(e);
                    }
                }

                $timeout(function(){
                    //$ctrlService.selectedSlide($scope.ctrlName, $scope.slides[1]);

                }, 1);
		}]);
    </script>
    <style type="text/css">
        .directive
        {
            height: 300px;
        }
        button
        {
            margin: 5px 0;
            width: 125px;
        }
        .inline-block
        {
            display: inline-block;
            margin: 3px 0;
        }
        .inline-button
        {
            width: 85px;
            margin-right: 3px
        }
        .slide-content
        {
            padding: 30% 10px;
            font-size: 2em;
            text-align: center;
        }
    </style>
</head>
<body>
	<div class="header">
        <div class="header-content">
		    <h1><span style="color:#c60d0d">IntegralUI</span> Studio <span style="font-size:0.75em; font-style:italic">for Web</span></h1>
        </div>
        <hr class="head-separator" />
    </div>
    <div class="content" ng-app="appModule">
        <div class="feature" ng-controller="appCtrl">
	        <h2 class="feature-title">SlideBar / Add Remove Slides</h2>
	        <div class="feature-content">
                <iui-slidebar name="{{ctrlName}}" class="directive" slides="slides" events="ctrlEvents">
                    <iui-slide ng-repeat="slide in slides" name="{{slide.name}}">
                        <div class="slide-content">
                            {{slide.name}}
                        </div>
                    </iui-slide>
                </iui-slidebar>
                <div class="control-panel" align="center" style="width:150px">
                    <button ng-click="add()">Add</button><br />
                    <button ng-click="insertAfter()" ng-disabled="disableButtons">Insert After</button><br />
                    <button ng-click="insertBefore()" ng-disabled="disableButtons">Insert Before</button><br />
                    <div class="inline-block">
                       <button class="inline-button" ng-click="insertAt()">Insert At</button><input ng-model="insertPos" type="number" min="0" max="100" style="width:35px" />
                    </div>
                    <button ng-click="remove()" ng-disabled="disableButtons">Remove</button><br />
                    <div class="inline-block">
                        <button class="inline-button" ng-click="removeAt()" ng-disabled="disableButtons">Remove At</button><input ng-model="removePos" type="number" min="0" max="100" style="width:35px" /><br />
                    </div>
                    <button ng-click="clear()" ng-disabled="disableButtons">Clear</button>
                </div>
                <br style="clear:both;"/>
                <div class="feature-help">
                    <p>In this sample you can create and/or modify a SlideBar using several different methods:
                        <ul class="feature-points">
                            <li><span style="color:#c60d0d">addSlide</span> - adds a new slide</li>
                            <li><span style="color:#c60d0d">insertSlideAfter</span> - adds a new slide after specified slide (in this example the selected slide)</li>
                            <li><span style="color:#c60d0d">insertSlideAt</span> - adds a new slide at specified position</li>
                            <li><span style="color:#c60d0d">insertSlideBefore</span> - adds a new slide before specified slide (in this example the selected slide)</li>
                            <li><span style="color:#c60d0d">removeSlide</span> - removes a slide (in this sample the selected slide)</li>
                            <li><span style="color:#c60d0d">removeSlideAt</span> - removes a slide at specified position from parent collection</li>
                            <li><span style="color:#c60d0d">clearSlides</span> - removes all slides</li>
                        </ul>
                    </p>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
